<?php
namespace app\home\validate;

use think\Validate;
use app\home\validate\Base;

class Transfer extends Base
{
    protected $rule = [
        'name'            => 'require|check_name:name',
        'money'           => 'require|number|isMoney:money',
        'wallet_type'     => 'require|in:2,4,6',
    ];

    protected $message = [
        'money.require'           => '请输入金额',
        'money.number'            => '金额格式错误',
        'money.isMoney'           => '金额格式错误',
        'wallet_type.in'          => '请选择钱包类型',
        'wallet_type.require'     => '请选择钱包类型',
        'name.require'            => '请输入转账会员',
        'name.check_name'         => '会员不存在',
    ];
    /**
     * 会员是否存在
     * @param int       $name     用户名
     * @return bool
     */
    protected function check_name($name)
    {
        $id =  db('user')
                ->where('user_name',$name)
                ->value('id');
        if ($id) {
            return true;
        }else{
            return false;
        }
    }
}